<template>
  <div class="promotion-page">
    <div class="chose-board">
    </div>
    <div class="list" style="height: 480px">
      <tableCom :data="data" :column="column" :operatesCol="operatesCol">
        <!-- <template slot="option">
          <div class="table-com-td item-option">
            晋级
          </div>
        </template> -->
      </tableCom>
    </div>
    <div class="homeBtn">
      <van-button style="width: 100%; height: 6vh; border-radius: 0.3rem" @click="toSubmit"
        color="linear-gradient(to right, #5c79f7, #5c74f4)">提交分数</van-button>
    </div>
  </div>
</template>

<script>
import tableCom from "@/components/tableCom.vue";
export default {
  name: "PromotionPage",
  components: { tableCom },
  props: {
    data: {
      type: Array,
      default: [],
    },
  },
  data() {
    return {
      tabBackColor: 0,
      column: [
        {
          label: "号码牌",
          prop: "name",
          width: 100,
          isSort: true, // 是否可排序
          SortFun: this.SortCardFun, //排序方法
          SortType: true, //排序状态
          canChange: false, //是否可切换成input框
        },
        {
          label: "总分",
          prop: "scoreRatio",
          isSort: true,
          SortFun: this.SortAllFun,
          SortType: true,
          canChange: true,
        },
      ],
      operatesCol: [
        {
          name: "修改",
          isShowName: false,
          icon: "records",
          methods: (row) => {
            this.$set(row, "isChange", !row.isChange);
            // row.isChange = !row.isChange
            console.log(row);
          },
        },
        {
          name: "删除",
          isShowName: false,
          icon: "delete",
          methods: (row) => {
            console.log(row);
          },
        },
      ],
    };
  },
  methods: {
    choseTabs() { },
    SortCardFun(list, item) {
      item.SortType = !item.SortType;
      this.data = list.sort((a, b) => {
        if (item.SortType) {
          return a.name > b.name ? 1 : -1;
        } else {
          return a.name < b.name ? 1 : -1;
        }
      });
      console.log(this.data);
    },
    SortAllFun(list, item) {
      item.SortType = !item.SortType;
      this.data = list.sort((a, b) => {
        if (item.SortType) {
          return a.scoreRatio > b.scoreRatio ? 1 : -1;
        } else {
          return a.scoreRatio < b.scoreRatio ? 1 : -1;
        }
      });
      console.log(this.data);
    },
    toSubmit() {
      this.$axios.post(`score/scoreRecord/submit`, this.addUsers).then((res) => {
        this.getBuyUsers()
      });
    },
  },
};
</script>

<style lang="less" scoped>
.promotion-page {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 5px 10px;

  .chose-board {
    padding: 0 0.4rem;

    .promBtn {
      margin-bottom: 0.3rem;
    }

    .chose-tabs {
      display: flex;

      .tabsInfo {
        background: #32324e;
        padding: 0.2rem;
        border-radius: 0.05rem;
        width: 2rem;
        text-align: center;
        color: rgba(255, 255, 255, 0.8);
        font-size: 0.2rem;
        margin-right: 0.3rem;

        .tInfoTop {
          margin-bottom: 0.2rem;
        }

        .tabStatus {
          background: #2b4856;
          color: #6bc6a2;
          border-radius: 0.2rem;
          width: 80%;
          margin: auto;
        }
      }
    }
  }

  .homeBtn {
    background: #27283d;
    height: 12vh;
    padding: 0 0.2rem;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
